﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using MS.InformationManagement.Presenter.DocumentsUploader;
using System.Collections.Generic;
using MS.InformationManagement.Support.Constants;
using System.Web.UI.WebControls;
using MS.InformationManagement.Support;
using MS.InformationManagement.Presenter.Support;

namespace MS.InformationManagement.WP.Layouts.MS.InformationManagement.WP
{
    public partial class DocumentLibraryUploaderFiles : BaseApplicationPage, IDocumentsUploaderView
    {

        #region fields

        DocumentsUploaderPresenter _presenter;

        #endregion

        #region Properties

        public List<DAL.DocumentCenter.FileEntity> SelectedFiles 
        {
            get { return this.dUpload.Files; } 
        }

        public string ListID { get { return Page.Request.QueryString["lstID"]; } }

        #endregion

        #region Form Events

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            dUpload.LocalFilesOnly = true;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            _presenter = new DocumentsUploaderPresenter(this);
        }

        protected void SaveAction(object sender, EventArgs e)
        {
            try
            {
                if (dUpload.Files == null || dUpload.Files.Count == 0)
                    throw new Exception(ExceptionConstants.ERROR_ARCHIVO_NULO);
                _presenter.HandelSave();
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
        }

        protected void CancelAction(object sender, EventArgs e)
        {
            this.GoCurrentUserHome();
        }

        #endregion

        #region Implemented Methods

        public void Success()
        {
            WebControl[] controls = new WebControl[]{ btnCancelar, btnGuardar };
            HandleSuccessRedirect(GlobalConstants.SUCCESS_UPLOADED_FILES, controls, true);
        }

        #endregion
    }
}
